/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package comServer;

import com.sun.management.OperatingSystemMXBean;
import java.io.*;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Habib
 */
public class ProcessImpl extends UnicastRemoteObject implements Processes {

    public ProcessImpl() throws RemoteException {
    }

    //private String [] cmds;
    public void getListOfProcessus() {
        //Runtime runtime = Runtime.getRuntime();
        try {
            String[] cmd = {"cmd", "/c", "tasklist"};
            Process proc = Runtime.getRuntime().exec(cmd);
            InputStream inputstream = proc.getInputStream();
            InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
            BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
            String line;
            while ((line = bufferedreader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void getFreeMemory() {
        String[] cmd = {"cmd", "/c", "wmic os get freephysicalmemory"};
        Process mem=null;
        try {
            mem = Runtime.getRuntime().exec(cmd);
            System.out.println(mem);
        } catch (IOException ex) {
            Logger.getLogger(ProcessImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        InputStream inputstream = mem.getInputStream();
        InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
        BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
        String line;
        try {
            while ((line = bufferedreader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException ex) {
            Logger.getLogger(ProcessImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void getCPU() {
        String[] cmd = {"cmd", "/c", "wmic cpu get loadpercentage"};
        Process load=null;
        try {
            load = Runtime.getRuntime().exec(cmd);
        } catch (IOException ex) {
            Logger.getLogger(ProcessImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        InputStream inputstream = load.getInputStream();
        InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
        BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
        String line;
        try {
            while ((line = bufferedreader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException ex) {
            Logger.getLogger(ProcessImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

